CC = clang
CXX = clang++
CFLAGS = -fprofile-instr-generate -fcoverage-mapping -fcoverage-mcdc 
CXXFLAGS = -std=c++17 -isystem /usr/include/gtest -pthread -fprofile-instr-generate -fcoverage-mapping 
LDFLAGS = -pthread
LIBS = /usr/local/lib/libgtest.a /usr/local/lib/libgtest_main.a

all: html

clean:
	rm -rf test default.profraw math_functions.o test.profdata output

html: test
	./test
	llvm-profdata merge -sparse default.profraw -o test.profdata
	llvm-cov report ./test -instr-profile=test.profdata -show-mcdc-summary
	llvm-cov show ./test -instr-profile=test.profdata -show-mcdc-summary -format=html -output-dir=./output

test: math_functions.o test.cpp
	$(CXX) $(CXXFLAGS) $^ $(LDFLAGS) $(LIBS) -o $@

math_functions.o: math_functions.c math_functions.h
	$(CC) $(CFLAGS) -c $< -o $@

.PHONY: all clean html